package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;

import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/11/5 18:29
 * @desrcption: 流转条件日期枚举类
 */
public enum  DateEnum {

    /**
     * 流转条件日期枚举
     */

    TODAY("today", "enum.date.memo.today"),
    YESTERDAY("yesterday", "enum.date.memo.yesterday"),
    THIS_WEEK("thisWeek", "enum.date.memo.this_week"),
    LAST_WEEK("lastWeek", "enum.date.memo.last_week"),
    THIS_MONTH("thisMonth", "enum.date.memo.this_month"),
    LAST_MONTH("lastMonth", "enum.date.memo.last_month"),
    TOMORROW("tomorrow", "enum.date.memo.tomorrow"),
    NEXT_WEEK("next_week", "enum.date.memo.next_week"),
    NEXT_MONTH("next_month", "enum.date.memo.next_month"),
    THIS_QUARTER("this_quarter", "enum.date.memo.this_quarter"),
    LAST_QUARTER("last_quarter", "enum.date.memo.last_quarter"),
    NEXT_QUARTER("next_quarter", "enum.date.memo.next_quarter"),
    FIRST_HALF_YEAR("first_half_year", "enum.date.memo.first_half_year"),
    SECOND_HALF_YEAR("second_half_year", "enum.date.memo.second_half_year"),
    THIS_YEAR("this_year", "enum.date.memo.this_year"),
    LAST_YEAR("last_year", "enum.date.memo.last_year"),
    NEXT_YEAR("next_year", "enum.date.memo.next_year"),
    ;

    private String value;

    private String memo;

    DateEnum(String value, String memo){
        this.value = value;
        this.memo = memo;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public static DateEnum getDateEnum(String value) {
        for (DateEnum date: values()) {
            if(date.getValue().equals(value)){
                return date;
            }
        }
        return null;
    }

    public static String getDateEnumMemo(String value) {
        DateEnum dateEnum = getDateEnum(value);
        return Objects.isNull(dateEnum) ? "" : dateEnum.getMemo();
    }
}
